package com.study.blockingqueue;

import java.util.EnumMap;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 消费者
 * 
 * @author wali-pp
 * 
 */
public class Consumer implements Runnable {

	private final BlockingQueue<Integer> queue;
//	private final ConcurrentHashMap<Character, Character> hashMap = new ConcurrentHashMap<Character, Character>();

	public Consumer(BlockingQueue<Integer> q) {
		this.queue = q;
	}

	void consume(Integer i) {
//		try {
//			Thread.sleep(10 * 1000);
//		} catch (InterruptedException e) {
//			e.printStackTrace();
//		}
		System.out.println("消费：" + i);
	}

	@Override
	public void run() {
		try {
			while (true) {
//				if(queue.peek() == 4)
//				{
//					System.out.println("queue.peek()==4");
//					queue.remove(queue.peek());
//					continue;
//				}
				final Integer take = queue.take();
				System.out.println("take = " + take);
//				hashMap.put(take, take);
				consume(take);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
